#include <iostream>
#include <string>
#include <map>
using namespace std;


bool err(const string& s){
	int num=0;
	int sum=0;
	for(int i=0;i<s.length();i++){
		if(num == 0  &&  s[i] == '0'  &&  (i == s.length()-1  ||  !(s[i+1] == '.'  ||  s[i+1] == ':')))
			return true;
		if(s[i] == ':'  &&  sum != 3)
			return true;
		if(s[i] == '.'  &&  sum >= 3)
			return true;
		if(!((s[i] >= '0'  &&  s[i] <= '9')  ||  (s[i] == '.'  ||  s[i] == ':')))
			return true;
		if(s[i] >= '0'  &&  s[i] <= '9')
			num = num*10+(s[i]-'0');
		if((sum == 4  &&  num > 65535)  ||  (sum < 4  &&  num > 255))
			return true;
		if(s[i] == '.'){
			sum++;
			num = 0;
		}
		if(s[i] == ':'){
			sum++;
			num = 0;
		}
	}
	if(sum != 4)
		return true;
	return false;
}


int main(){
	int n;
	cin>>n;
	map<string,int> m;
	for(int i=0;i<n;i++){
		cout<<"["<<i<<"]"; 
		string a,b;
		cin>>a>>b;
		if(err(b)){
			cout<<"ERR"<<endl;
			continue;
		}
		if(a == "Server"){
			if(m[b] != 0)
				cout<<"FAIL"<<endl;
			else{
				cout<<"OK"<<endl;
				m[b] = i+1;
			}
		}
		else{
			if(m[b] == 0)
				cout<<"FAIL"<<endl;
			else
				cout<<m[b]<<endl;
		}
	}
	return 0;
}
